package customerEnter.Frame.filter;

import java.io.IOException;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

/**
 * 編碼過濾器
 * 
 * 类名称：EncodingFilter 类描述： 创建人：dy 创建时间：2016-3-25 上午9:35:03
 * 
 */
public class EncodingFilter implements Filter {
	private String				encoding;
	private Map<String, String>	params	= new HashMap<String, String>();

	// 项目结束时
	public void destroy() {
		System.out.println("銷毀編碼");
		params = null;
		encoding = null;
	}

	// 請求過來的時候
	public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws IOException,
			ServletException {
		req.setCharacterEncoding(encoding);

		chain.doFilter(req, resp);
	}

	// 初始化的時候
	public void init(FilterConfig config) throws ServletException {
		encoding = config.getInitParameter("encoding");
		for (@SuppressWarnings("rawtypes")
		Enumeration e = config.getInitParameterNames(); e.hasMoreElements();) {
			String name = (String) e.nextElement();
			String value = config.getInitParameter(name);
			params.put(name, value);
		}
	}
}
